package concept.chapter7.conversion;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Conversion
{
	public static void main(String[] args)
	{
		List<String> list = new ArrayList<String>();
		list.add("a");
		list.add("b");
		list.add("c");
		
		String[] array = list.toArray(new String[0]);
		List<String> anotherList = Arrays.asList(array);
		
		System.out.println("Original list: ");
		for(String s:list)
			System.out.println(s);
		
		System.out.println("Original array: ");
		for(String s:array)
			System.out.println(s);

		//modify list
		list.remove("d");
		//modify array
		array[array.length-1] = "foo!";
		
		System.out.println("\nCurrent list: ");
		for(String s:list)
			System.out.println(s);

		System.out.println("Current array: ");
		for(String s:array)
			System.out.println(s);
		
		System.out.println("Array converted list: ");
		for(String s:anotherList)
			System.out.println(s);
		
		//modify anotherList
		anotherList.set(array.length-1, "FOO!");

		System.out.println("\nArray with its converted list modified: ");
		for(String s:array)
			System.out.println(s);
	}

}
